// SISTEMA.: INFOSEG/IDENTIFICACAO CRIMINAL
// PROGRAMA: INFSEG01
// ANALISTA: SOLON MIRANDA
// DATA: 03/04/2006
// OBJETIVO:- ATUALIZACAO DO ARQUIVO DO INDICE NACIONAL LAY-OUT
// DOS REGISTROS VERSAO 1
// ULTIMA ATUALIZACAO * EM 03/07/2007
// OBSERVACAO:- UTILIZAR O JCL INFSEG01, PARA RODAR EM BATCH
// OU UTILIZAR O JCL AUTOMATICO E PERIODICO DE MIRANDA

package br.com.vti.sisp_sicrim.antigo.controller.programa;

import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.apache.commons.lang3.StringUtils;

import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.model.Infseg1;
import br.com.vti.sisp_sicrim.antigo.model.SicCadastro;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Infseg01 OBJETIVO:- ATUALIZACAO DO ARQUIVO DO INDICE NACIONAL LAY-OUT DOS REGISTROS VERSAO 1 ULTIMA ATUALIZACAO * EM 03/07/2007 OBSERVACAO:- UTILIZAR O JCL INFSEG01, PARA RODAR EM BATCH OU
 * UTILIZAR O JCL AUTOMATICO E PERIODICO DE MIRANDA *
 * 
 * @author Incode - Data: mai/2014
 * 
 */

public class Infseg01 {
	// Views utilizadas
	SicCadastro criminalView = new SicCadastro();
	// Telas/relatorios utilizados
	// Includes utilizados
	Infseg1 infseg1 = new Infseg1();
	// Areas globais / session // Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();
	FileWriter arquivo1;
	
	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;
	private String nome;
	private int horax;
	private int horat;
	private int contTr10 = 0;
	private int contTr11 = 0;
	private int contTr12 = 0;
	private int contGeral = 0;
	private int cnome = 0;
	private int cmae = 0;
	private int cpai = 0;
	private String[] jObservacoes;

	public Infseg01(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	public void executar() {
		try {
			main();
		} catch (Exception e) {
			throw new ExceptionProgram(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main() throws Exception {
		arquivo1 = new FileWriter(UtilBean.pathFiles()+"arquivo1");
		infseg1.tr13Cr = "\r";
		// Par�grafo: l1()
		while (criminalView.leituradescTipoRegFaixa("IN", "AL")) {
			if (!(criminalView.getDataDocAtu() > 20070521)) {
				continue;
			}
			cnome = 0;
			cmae = 0;
			cpai = 0;
			nome = criminalView.getNomeCompleto();
			funcoes.validnom(nome);
			if (funcoes.err != 0) {
				cnome = 1;
				UtilBean.mensagemTexto("# ERRO NOME:", criminalView.getTipoReg(), criminalView.getRegEstadualGeral(), UtilBean.subStr(nome, 0, 30));
			}

			nome = criminalView.getNomePai();
			funcoes.validnom(nome);
			if (funcoes.err != 0) {
				cpai = 1;
				UtilBean.mensagemTexto("# ERRO NOME PAI:", criminalView.getTipoReg(), criminalView.getRegEstadualGeral(), UtilBean.subStr(nome, 0, 30));
			}

			nome = criminalView.getNomeMae();
			funcoes.validnom(nome);
			if (funcoes.err != 0) {
				cmae = 1;
				UtilBean.mensagemTexto("# ERRO NOME MAE:", criminalView.getTipoReg(), criminalView.getRegEstadualGeral(), UtilBean.subStr(nome, 0, 30));
			}

			if (cnome == 0)
			// && CPAI = 0 && CMAE = 0
			{
				switch (criminalView.getTipoReg()) {
				case "IN": {
					contTr10 += 1;
					break;
				}
				case "EX": {
					contTr12 += 1;
					break;
				}
				case "AL": {
					contTr11 += 1;
					break;
				}
				default: {
					continue;
				}
				}
			}

		}
		criminalView.fecha();
		infseg1.headerTipoReg = 00;
		infseg1.headerUfReg = "MA";
		infseg1.headerTipoArq = "IND";
		// ARQUIVO DE ATUALIZACAO

		infseg1.headerDataEnvio = UtilBean.obtemDataCorrente();
		horax = Integer.parseInt((new SimpleDateFormat("HHmmssS").format(Calendar.getInstance().getTime())));
		infseg1.headerHoraEnvio = horax;
		infseg1.headerQtTr10 = contTr10;
		infseg1.headerQtTr11 = contTr11;
		infseg1.headerQtTr12 = contTr12;
		infseg1.headerQtTr13 = 0;
		infseg1.headerQtTr14 = 0;
		infseg1.headerFiller1 = StringUtils.repeat(" ", 100);
		infseg1.headerFiller2 = StringUtils.repeat(" ", 191);
		infseg1.headerCr = "\r";
		contGeral = contTr10 + contTr11 + contTr12;
		UtilBean.mensagemTexto("TOTAL INCLUSAO        (TR10) =", contTr10);
		UtilBean.mensagemTexto("TOTAL ALTERACAO       (TR11) =", contTr11);
		UtilBean.mensagemTexto("TOTAL EXCLUSAO        (TR12) =", contTr12);
		// UtilBean.mensagemTexto("TOTAL GERAL (TR10+TR11+TR12) =" contGeral);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 0, 2, "N", infseg1.headerTipoReg);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 2, 2, "A", infseg1.headerUfReg);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 4, 3, "A", infseg1.headerTipoArq);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 7, 8, "N", infseg1.headerDataEnvio);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 15, 6, "N", infseg1.headerHoraEnvio);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 21, 6, "N", infseg1.headerQtTr10);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 27, 6, "N", infseg1.headerQtTr11);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 33, 6, "N", infseg1.headerQtTr12);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 39, 6, "N", infseg1.headerQtTr13);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 45, 6, "N", infseg1.headerQtTr14);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 51, 100, "A", infseg1.headerFiller1);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 151, 191, "A", infseg1.headerFiller2);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 342, 2, "A", infseg1.headerFinalCampo);
		infseg1.regHeader = UtilBean.moveSubstring(infseg1.regHeader, 344, 2, "A", infseg1.headerCr);
		arquivo1.write(infseg1.regHeader);
		//dao.rollback();
		// Par�grafo: l2()
		while (criminalView.leituradescTipoRegFaixa("IN", "AL")) {
			if (!(criminalView.getDataDocAtu() > 20070521)) {
				continue;
			}
			nome = criminalView.getNomeCompleto();
			funcoes.validnom(nome);
			if (funcoes.err == 0) {
				switch (criminalView.getTipoReg()) {
				case "IN": {
					regTr10();
					break;
				}
				case "EX": {
					regTr12();
					break;
				}
				case "AL": {
					regTr11();
					break;
				}
				default: {
					continue;
				}
				}
			}

		}
		criminalView.fecha();

		infseg1.footerTipoReg = 99;
		infseg1.footerFiller1 = StringUtils.repeat(" ", 121);
		infseg1.footerFiller2 = StringUtils.repeat(" ", 219);
		infseg1.footerCr = "\r";
		infseg1.regFooter = UtilBean.moveSubstring(infseg1.regFooter, 0, 2, "N", infseg1.footerTipoReg);
		infseg1.regFooter = UtilBean.moveSubstring(infseg1.regFooter, 2, 121, "A", infseg1.footerFiller1);
		infseg1.regFooter = UtilBean.moveSubstring(infseg1.regFooter, 123, 219, "A", infseg1.footerFiller2);
		infseg1.regFooter = UtilBean.moveSubstring(infseg1.regFooter, 342, 2, "A", infseg1.footerFinalCampo);
		infseg1.regFooter = UtilBean.moveSubstring(infseg1.regFooter, 344, 2, "A", infseg1.footerCr);
		arquivo1.write(infseg1.regFooter);
		////dao.rollback();
		UtilBean.mensagemTexto("*** OK. FIM DA GERACAO DO ARQUIVO CRIMINAL ***");
		arquivo1.close();
	}

	private void regTr10() throws Exception {
		infseg1.tr10TipoReg = 10;
		infseg1.tr10DataAtualizaUf = criminalView.getDataDocAtu();
		horat = criminalView.getHoraAtu();
		infseg1.tr10HoraAtualizaUf = horat;
		infseg1.tr10UfRegCriminal = "MA";
		infseg1.tr10ChavePrimariaRgIgUf = String.valueOf(criminalView.getRegEstadualGeral());
		infseg1.tr10NomeCompleto = criminalView.getNomeCompleto();
		nome = criminalView.getNomePai();
		funcoes.validnom(nome);
		if (funcoes.err != 0) {
			infseg1.tr10NomePai = " ";
		} else {
			infseg1.tr10NomePai = criminalView.getNomePai();
		}

		nome = criminalView.getNomeMae();
		funcoes.validnom(nome);
		if (funcoes.err != 0) {
			infseg1.tr10NomeMae = " ";
		} else {
			infseg1.tr10NomeMae = criminalView.getNomeMae();
		}

		infseg1.tr10DataNasc = criminalView.getDataNasc();
		if (criminalView.getSexo() != 0) {
			if (criminalView.getSexo() == 1) {
				infseg1.tr10Sexo = "M";
			} else {
				infseg1.tr10Sexo = "F";
			}

		} else {
			infseg1.tr10Sexo = " ";
		}

		infseg1.tr10Cutis = criminalView.getCodigoCutis();
		infseg1.tr10Naturalidade = criminalView.getNaturalidade();
		infseg1.tr10UfNaturalidade = criminalView.getUfNaturalidade();
		infseg1.tr10Nacionalidade = criminalView.getNacionalidade();
		infseg1.tr10NacionalidadeEstrang = 0000;
		infseg1.tr10TipoProprietarioArma = 00;
		infseg1.tr10RegistroGeral = String.valueOf(criminalView.getRegEstadualGeral());
		infseg1.tr10UfRegEstadualGeral = "MA";
		if (criminalView.getDataDocAtu() == 0) {

			infseg1.tr10DataUltimaMovimentUf = String.valueOf(UtilBean.obtemDataCorrente());
		} else {

			infseg1.tr10DataUltimaMovimentUf = String.valueOf(criminalView.getDataDocAtu());
		}

		infseg1.tr10PossuiInquerito = criminalView.getInqueritoPolicial();
		infseg1.tr10PossuiArma = criminalView.getPossuiArma();
		infseg1.tr10PossuiProcesso = criminalView.getPossuiProcesso();
		if (criminalView.getObservacao(11).trim().equals("")) {
			infseg1.tr10PossuiProcesso = "N";
		} else {
			infseg1.tr10PossuiProcesso = "S";
		}

		if (criminalView.getFalecido().trim().equals("")) {
			infseg1.tr10Falecido = "N";
		} else {
			infseg1.tr10Falecido = criminalView.getFalecido();
		}

		if (criminalView.getPossuiMandatoAberto().equals("S")) {
			infseg1.tr10PossuiMandatoPAberto = "S";
		} else {
			infseg1.tr10PossuiMandatoPAberto = "N";
		}

		infseg1.tr10Foragido = " ";
		infseg1.tr10CumprindoPena = " ";
		jObservacoes[4] = criminalView.getObservacao(4);
		if (UtilBean.subStr(jObservacoes[4], 9, 12).equals("NARCOTRAFICO")) {
			infseg1.tr10Narcotrafico = "S";
		} else {
			infseg1.tr10Narcotrafico = "N";
		}

		infseg1.tr10InformaPenitenciarias = " ";
		infseg1.tr10Imagens = " ";
		infseg1.tr10Flag06 = " ";
		infseg1.tr10Flag07 = " ";
		infseg1.tr10Flag08 = " ";
		// TR10-UF-ORIGEM := ' '

		infseg1.tr10UfOrigem = "  ";
		infseg1.tr10Cr = "\r";
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 0, 2, "N", infseg1.tr10TipoReg);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 2, 8, "N", infseg1.tr10DataAtualizaUf);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 10, 6, "N", infseg1.tr10HoraAtualizaUf);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 16, 2, "A", infseg1.tr10UfRegCriminal);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 18, 20, "A", infseg1.tr10ChavePrimariaRgIgUf);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 38, 70, "A", infseg1.tr10NomeCompleto);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 108, 70, "A", infseg1.tr10NomePai);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 178, 70, "A", infseg1.tr10NomeMae);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 248, 8, "N", infseg1.tr10DataNasc);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 256, 1, "A", infseg1.tr10Sexo);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 257, 2, "N", infseg1.tr10Cutis);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 259, 35, "A", infseg1.tr10Naturalidade);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 294, 2, "A", infseg1.tr10UfNaturalidade);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 296, 2, "N", infseg1.tr10Nacionalidade);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 298, 4, "N", infseg1.tr10NacionalidadeEstrang);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 302, 2, "N", infseg1.tr10TipoProprietarioArma);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 304, 15, "A", infseg1.tr10RegistroGeral);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 319, 2, "A", infseg1.tr10UfRegEstadualGeral);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 321, 8, "A", infseg1.tr10DataUltimaMovimentUf);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 329, 1, "A", infseg1.tr10PossuiInquerito);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 330, 1, "A", infseg1.tr10PossuiArma);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 331, 1, "A", infseg1.tr10PossuiProcesso);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 332, 1, "A", infseg1.tr10Falecido);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 333, 1, "A", infseg1.tr10PossuiMandatoPAberto);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 334, 1, "A", infseg1.tr10Foragido);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 335, 1, "A", infseg1.tr10CumprindoPena);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 336, 1, "A", infseg1.tr10Narcotrafico);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 337, 1, "A", infseg1.tr10InformaPenitenciarias);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 338, 1, "A", infseg1.tr10Imagens);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 339, 1, "A", infseg1.tr10Flag06);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 340, 1, "A", infseg1.tr10Flag07);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 341, 1, "A", infseg1.tr10Flag08);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 342, 2, "A", infseg1.tr10UfOrigem);
		infseg1.regTr10 = UtilBean.moveSubstring(infseg1.regTr10, 344, 2, "A", infseg1.tr10Cr);
		arquivo1.write(infseg1.regTr10);
		//dao.rollback();
	}

	private void regTr11() throws Exception {
		infseg1.tr11TipoReg = 11;
		infseg1.tr11DataAtualizaUf = criminalView.getDataDocAtu();
		horat = criminalView.getHoraAtu();
		infseg1.tr11HoraAtualizaUf = horat;
		infseg1.tr11UfRegCriminal = "MA";
		infseg1.tr11ChavePrimariaRgIgUf = String.valueOf(criminalView.getRegEstadualGeral());
		infseg1.tr11NomeCompleto = criminalView.getNomeCompleto();
		nome = criminalView.getNomePai();
		funcoes.validnom(nome);
		if (funcoes.err != 0) {
			infseg1.tr11NomePai = " ";
		} else {
			infseg1.tr11NomePai = criminalView.getNomePai();
		}

		nome = criminalView.getNomeMae();
		funcoes.validnom(nome);
		if (funcoes.err != 0) {
			infseg1.tr11NomeMae = " ";
		} else {
			infseg1.tr11NomeMae = criminalView.getNomeMae();
		}

		infseg1.tr11DataNasc = criminalView.getDataNasc();
		if (criminalView.getSexo() != 0) {
			if (criminalView.getSexo() == 1) {
				infseg1.tr11Sexo = "M";
			} else {
				infseg1.tr11Sexo = "F";
			}

		} else {
			infseg1.tr11Sexo = " ";
		}

		infseg1.tr11Cutis = criminalView.getCodigoCutis();
		infseg1.tr11Naturalidade = criminalView.getNaturalidade();
		infseg1.tr11UfNaturalidade = criminalView.getUfNaturalidade();
		infseg1.tr11Nacionalidade = criminalView.getNacionalidade();
		infseg1.tr11NacionalidadeEstrang = 0000;
		infseg1.tr11TipoProprietarioArma = 00;
		infseg1.tr11RegistroGeral = String.valueOf(criminalView.getRegEstadualGeral());
		infseg1.tr11UfRegEstadualGeral = "MA";
		if (criminalView.getDataDocAtu() == 0) {

			infseg1.tr11DataUltimaMovimentUf = String.valueOf(UtilBean.obtemDataCorrente());
		} else {

			infseg1.tr11DataUltimaMovimentUf = String.valueOf(criminalView.getDataDocAtu());
		}

		infseg1.tr11PossuiInquerito = criminalView.getInqueritoPolicial();
		infseg1.tr10PossuiArma = criminalView.getPossuiArma();
		infseg1.tr11PossuiProcesso = criminalView.getPossuiProcesso();
		if (criminalView.getObservacao(1).trim().equals("")) {
			infseg1.tr11PossuiProcesso = "N";
		} else {
			infseg1.tr11PossuiProcesso = "S";
		}

		infseg1.tr11Falecido = criminalView.getFalecido();
		infseg1.tr10PossuiMandatoPAberto = criminalView.getPossuiMandatoAberto();
		if (infseg1.tr10PossuiMandatoPAberto.trim().equals("")) {
			infseg1.tr10PossuiMandatoPAberto = "N";
		}

		infseg1.tr11Foragido = " ";
		infseg1.tr11CumprindoPena = " ";
		jObservacoes[4] = criminalView.getObservacao(4);
		if (UtilBean.subStr(jObservacoes[4], 9, 12).equals("NARCOTRAFICO")) {
			infseg1.tr11Narcotrafico = "S";
		} else {
			infseg1.tr11Narcotrafico = "N";
		}

		infseg1.tr10InformaPenitenciarias = " ";
		infseg1.tr11InformaPenitenciarias = " ";
		infseg1.tr11Imagens = " ";
		infseg1.tr11Flag06 = " ";
		infseg1.tr11Flag07 = " ";
		infseg1.tr11Flag08 = " ";
		infseg1.tr11UfOrigem = "  ";
		infseg1.tr11Cr = "\r";
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 0, 2, "N", infseg1.tr11TipoReg);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 2, 8, "N", infseg1.tr11DataAtualizaUf);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 10, 6, "N", infseg1.tr11HoraAtualizaUf);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 16, 2, "A", infseg1.tr11UfRegCriminal);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 18, 20, "A", infseg1.tr11ChavePrimariaRgIgUf);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 38, 70, "A", infseg1.tr11NomeCompleto);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 108, 70, "A", infseg1.tr11NomePai);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 178, 70, "A", infseg1.tr11NomeMae);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 248, 8, "N", infseg1.tr11DataNasc);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 256, 1, "A", infseg1.tr11Sexo);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 257, 2, "N", infseg1.tr11Cutis);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 259, 35, "A", infseg1.tr11Naturalidade);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 294, 2, "A", infseg1.tr11UfNaturalidade);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 296, 2, "N", infseg1.tr11Nacionalidade);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 298, 4, "N", infseg1.tr11NacionalidadeEstrang);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 302, 2, "N", infseg1.tr11TipoProprietarioArma);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 304, 15, "A", infseg1.tr11RegistroGeral);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 319, 2, "A", infseg1.tr11UfRegEstadualGeral);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 321, 8, "A", infseg1.tr11DataUltimaMovimentUf);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 329, 1, "A", infseg1.tr11PossuiInquerito);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 330, 1, "A", infseg1.tr11PossuiArma);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 331, 1, "A", infseg1.tr11PossuiProcesso);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 332, 1, "A", infseg1.tr11Falecido);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 333, 1, "A", infseg1.tr11PossuiMandatoPAberto);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 334, 1, "A", infseg1.tr11Foragido);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 335, 1, "A", infseg1.tr11CumprindoPena);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 336, 1, "A", infseg1.tr11Narcotrafico);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 337, 1, "A", infseg1.tr11InformaPenitenciarias);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 338, 1, "A", infseg1.tr11Imagens);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 339, 1, "A", infseg1.tr11Flag06);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 340, 1, "A", infseg1.tr11Flag07);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 341, 1, "A", infseg1.tr11Flag08);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 342, 2, "A", infseg1.tr11UfOrigem);
		infseg1.regTr11 = UtilBean.moveSubstring(infseg1.regTr11, 344, 2, "A", infseg1.tr11Cr);
		arquivo1.write(infseg1.regTr11);
		//dao.rollback();
	}

	private void regTr12() throws IOException {
		infseg1.tr12TipoReg = 12;
		infseg1.tr12DataAtualizaUf = criminalView.getDataDocAtu();
		horat = criminalView.getHoraAtu();
		infseg1.tr12HoraAtualizaUf = horat;
		infseg1.tr12UfRegCriminal = "MA";
		infseg1.tr12ChavePrimariaRgIgUf = String.valueOf(criminalView.getRegEstadualGeral());
		infseg1.tr12ChavePrimariaRgIgUf = String.valueOf(criminalView.getRegEstadualGeral());
		infseg1.tr12Filler1 = StringUtils.repeat(" ", 153);
		infseg1.tr12Filler2 = StringUtils.repeat(" ", 151);
		infseg1.tr12Cr = "\r";
		infseg1.regTr12 = UtilBean.moveSubstring(infseg1.regTr12, 0, 2, "N", infseg1.tr12TipoReg);
		infseg1.regTr12 = UtilBean.moveSubstring(infseg1.regTr12, 2, 8, "N", infseg1.tr12DataAtualizaUf);
		infseg1.regTr12 = UtilBean.moveSubstring(infseg1.regTr12, 10, 6, "N", infseg1.tr12HoraAtualizaUf);
		infseg1.regTr12 = UtilBean.moveSubstring(infseg1.regTr12, 16, 2, "A", infseg1.tr12UfRegCriminal);
		infseg1.regTr12 = UtilBean.moveSubstring(infseg1.regTr12, 18, 20, "A", infseg1.tr12ChavePrimariaRgIgUf);
		infseg1.regTr12 = UtilBean.moveSubstring(infseg1.regTr12, 38, 153, "A", infseg1.tr12Filler1);
		infseg1.regTr12 = UtilBean.moveSubstring(infseg1.regTr12, 191, 151, "A", infseg1.tr12Filler2);
		infseg1.regTr12 = UtilBean.moveSubstring(infseg1.regTr12, 342, 2, "A", infseg1.tr12FinalCampo);
		infseg1.regTr12 = UtilBean.moveSubstring(infseg1.regTr12, 344, 2, "A", infseg1.tr12Cr);
		arquivo1.write(infseg1.regTr12);
		//dao.rollback();
	}
}
